package com.rong.creatmodel.prototype.deep;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class AwareTest {
    public static void main(String[] args) throws  Exception {

        Aware aware = new Aware();
        Student student = new Student();
        student.setName("李四");
        aware.setStu(student);

//        // 浅克隆对象
//        Aware clone = aware.clone();
//        clone.getStu().setName("张三");
//
//        aware.show(); // 张三
//        clone.show(); //张三


        // 深克隆：创建对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\a.txt"));
        oos.writeObject(aware);
        oos.close();

        // 读取对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\a.txt"));
        Aware aware1 = (Aware)ois.readObject();
        ois.close();

        // 修改克隆后的对象
        aware1.getStu().setName("张三");
        aware.show(); // 李四
        aware1.show();//张三
    }
}
